#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 2e5 + 5;

int n, c;
int a[N];

int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n >> c;
  rep(i, 1, n) cin >> a[i];
  sort(a + 1, a + n + 1);
  int l = 1, r = 1;
  ll ans = 0;
  while (r <= n) {
    int l2 = l;
    while (l2 <= n && a[l2] == a[l]) l2++;

    while (r <= n && a[r] < a[l] + c) r++;
    if (r > n) break;
    if (a[r] == a[l] + c) {
      int r2 = r;
      while (r2 <= n && a[r2] == a[r]) r2++;
      ans += 1ll * (l2 - l) * (r2 - r);
      r = r2;
    }
    l = l2;
  }
  cout << ans;
  return 0;
}